﻿///<reference path="_moduleReferences.ts" />

module ScrambledEggs.Modules {
    export class Inventory implements IModule {

        private _onUpdate: () => void;

        constructor() {
        }

        initialize(gameState: GameStateProvider, onUpdate: () => void ) {
            this._onUpdate = onUpdate;
        }

        update(gameState: GameStateProvider, triggerSource: IModule): void {
            if (!gameState.State.Inventory["PenKey"]) {
                $("#inventory").hide();
                return;
            }

            var me = this;
            var inventory = $("#inventory").show();
            inventory.find("section").remove();

            for (var itemKey in gameState.State.Inventory) {
                var status = gameState.State.Inventory[itemKey];
                switch (itemKey) {
                    case "PenKey":
                        if(status == 1)
                            inventory.append("<section title=\"It's a key!\">&nbsp;/¨¨¨\\_______<br />|&nbsp;o&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_&nbsp;&nbsp;&nbsp;&nbsp;`.<br />&nbsp;\\___~^-´&nbsp;`^¨\"´</section>");
                        if (status == -1)
                            inventory.append("<section title=\"An unidentified Object.\">&nbsp;&nbsp;???&nbsp;&nbsp;</section>");
                        break;
                    default:
                        throw "Cannot display item of type " + itemKey;
                }
            }

            inventory.find("div").appendTo(inventory); // make the clear the last element again
        }        
    }
}